home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2000 #1 / Amiga Plus CD - 2000 - No. 1.iso / Tools / Dev / Sas-PPC / samplelib2 / dispatchppc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-12-03  |  2.5 KB  |  83 lines

  1. #define  _USEOLDEXEC_ 1
  2. #include <exec/types.h>
  3. #include <exec/nodes.h>
  4. #include <exec/memory.h>
  5. #include <exec/resident.h>
  6. #include <exec/libraries.h>
  7. #include <exec/execbase.h>
  8. #include <libraries/dos.h>
  9. #include <proto/exec.h>
  10. #include <proto/dos.h>
  11. #include <string.h>
  12. #include <dos/dostags.h>
  13. #include <PowerUP/PPCLib/Interface.h>
  14. #include <PowerUP/PPCLib/tasks.h>
  15. #include <PowerUP/PPCLib/ppc.h>
  16. #include <PowerUP/PPCLib/object.h>
  17. #include <PowerUP/PPCLib/message.h>
  18. #include <powerup/gcclib/powerup_protos.h>
  19.  
  20. #include "ppcdispatch.h"
  21.  
  22.  
  23. void _DispatchFunction(void)
  24. {
  25.     void *PPCPort;
  26.     void *PPCMsg;
  27.     void *ReplyPort;
  28.     void *msg;
  29.     struct PPCDispatchMsg *DispatchMsg;
  30.     long *ret;
  31.     struct TagItem MyTags[10];
  32.     struct StartupData *StartupData;
  33.     
  34.     StartupData    =(struct StartupData *) PPCGetTaskAttr(PPCTASKTAG_STARTUP_MSGDATA);
  35.  
  36.     if (ret = PPCAllocVec(sizeof(*ret), MEMF_ANY))
  37.     {
  38.       if (PPCPort=(void*) PPCGetTaskAttr(PPCTASKTAG_MSGPORT))
  39.       {
  40.         MyTags[0].ti_Tag = TAG_DONE;
  41.         if (ReplyPort = PPCCreatePort(MyTags))
  42.         {
  43.             if (PPCMsg = PPCCreateMessage(ReplyPort, sizeof(*ret)))
  44.             {
  45.                 __fpinit();
  46.                 while(1)
  47.                 {
  48.                     while ((msg = PPCGetMessage(PPCPort)) == NULL)
  49.                         PPCWaitPort(PPCPort);
  50.             
  51.                     DispatchMsg = (void *)PPCGetMessageAttr(msg, PPCMSGTAG_DATA);           
  52.              
  53.                     if (DispatchMsg->func == NULL)
  54.                     {
  55.                         /* signal to terminate */
  56.                         __fpterm();
  57.                         PPCReplyMessage(msg);
  58.                         break;
  59.                     }
  60.             
  61.                     *ret = DispatchMsg->func(DispatchMsg->r3, DispatchMsg->r4, DispatchMsg->r5,
  62.                                      DispatchMsg->r6, DispatchMsg->r7, DispatchMsg->r8,
  63.                                      DispatchMsg->r9, DispatchMsg->r10);
  64.             
  65.                     PPCReplyMessage(msg);
  66.                     PPCSendMessage(StartupData->MsgPort,
  67.                            PPCMsg,
  68.                            ret,
  69.                            sizeof(*ret),
  70.                            0x87654321);
  71.                     while (PPCGetMessage(ReplyPort) == NULL)
  72.                         PPCWaitPort(ReplyPort);
  73.                 }
  74.                 PPCDeleteMessage(PPCMsg);
  75.             }
  76.             PPCDeletePort(ReplyPort);
  77.         }
  78.         PPCFreeVec(ret);
  79.       }   
  80.         
  81.     }
  82. }
  83.